/* eslint-disable */
// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
import Vue from 'vue'
Date.prototype.Format = function (fmt) { //author: meizz
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

Vue.filter('formatDate', function (value) {
  if( typeof(value) === 'string') value = value.replace(/-/g,'/')
  let d = new Date(value)
  let month = d.getMonth() < 9 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1
  let day = d.getDate() < 10  ? '0' + d.getDate() : d.getDate()
  let ds = d.getFullYear() + '-' + month + '-' + day
  return ds
}) 

Vue.filter('IOSformatDate', function (value) {
  if( typeof(value) === 'string') value = value.replace(/-/g,'/')
  let d = new Date(value)
  let month = d.getMonth() < 9 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1
  let day = d.getDate() < 10  ? '0' + d.getDate() : d.getDate()
  let ds = d.getFullYear() + '/' + month + '/' + day
  return ds
}) 

/**
 * 订单状态
  public static final int NEW_ORDER_STATUS_1 =1;//租客提交，待房东确认
  public static final int NEW_ORDER_STATUS_2 =2;//房东已取消
  public static final int NEW_ORDER_STATUS_3 =3;//房东已签约，待租客签约
  public static final int NEW_ORDER_STATUS_4 =4;//待租客支付
  public static final int NEW_ORDER_STATUS_5 =5;//租客支付成功

  * 合同状态
  public static final int CONTRACT_STATUS_1 = 1; 合同状态 1 暂存 房东已签，租客待签
  public static final int CONTRACT_STATUS_2 = 2; 合同状态 2 生效 双方已签
  public static final int CONTRACT_STATUS_3 = 3; 合同状态 3 废除 解除合同

 * 合同状态过滤器
 */
Vue.filter('orderStatus2txt', function (status) {
  let txt = ''
  if (status === 0) txt = '待租客确认'
  if (status === 1) txt = '待房东确认'
  if (status === 2) txt = '房东已取消'
  if (status === 3) txt = '待签约'
  if (status === 4) txt = '待支付'
  if (status === 5) txt = '支付成功'
  if (status === 6) txt = '订单失效'
  return txt
})

/**
 * 订单状态转文本过滤器
 */
Vue.filter('contractStatus2txt', function (status) {
  let txt = '等待房东确认'
  if (status === 1) txt = '等待房东签约'
  if (status === 2) txt = '生效'
  if (status === 3) txt = '合同失效'
  return txt
})

/*
* 时间转化
*/

Date.prototype.fm = (time) => {
  tmp = new Date(time);
  let year = tmp.getFullYear()
  let month = tmp.getMonth()+1
  let date = tmp.getDate()
  let hours = tmp.getHours()
  let minutes = tmp.getMinutes()
  let seconds = tmp.getSeconds()
  return {
    minutes,
    seconds
  } 
}
